<?php require_once('../../core/import.php');?>
<?php User::Permission('ACCOUNT_UPDATE'); ?>
<?php
    if($_SERVER['REQUEST_METHOD']=='POST')
    {
        #图片处理
        $Result=Upload::Probe($_FILES['Logo'],Config::UPLOAD_ATTACHMENT_SIZE_IMAGE,Config::UPLOAD_ATTACHMENT_EXT_IMAGE,Config::PATH_UPLOAD_ATTACHMENT_TEMP);
        
        #如果重新上传了图片，处理
        $FileName=NULL;
        if($Result['error']!=UPLOAD_ERR_NO_FILE)    //如果上传了文件
        {
            switch($Result['error'])
            {
                case UPLOAD_ERR_OK:
                    $FileName=Upload::Execute($_FILES['Logo'],Config::PATH_UPLOAD_ATTACHMENT_TEMP);
                break;
                case Upload::UPLOAD_ERR_CUSTOM_EXT:
                    exit('{"Number":"2","Description":"LOGO格式不正确，只能是：'.join(',',Upload::$UPLOAD_EXT_IMAGE).'。"}');
                break;
                case Upload::UPLOAD_ERR_CUSTOM_SIZE:
                    exit('{"Number":"3","Description":"LOGO大小超过了限制，不能超过：'.Functions::SizeFormat(Config::UPLOAD_ATTACHMENT_SIZE_IMAGE).'。"}');
                break;
                default :
                    exit('{"Number":"4","Description":"LOGO上传失败。错误代码：'.$Result['error'].'，错误描述：'.$Result['message'].'。"}');
            }
        }
	  $Username=Functions::FormArgs('username');
	  $PassWord=Functions::FormArgs('Password');
	  $PassWord_Again=Functions::FormArgs('Password_again');
	  $id=Functions::FormArgs('ai');
	  if($PassWord!=$PassWord_Again)
	  {
		exit('{"Number":"4","Description":"两次密码输入不一致"}');	  
	  }
        #上传数据

	  $Data=array
		(
			'Username'=>$Username,
			'CompanyName'=>Functions::FormArgs('CompanyName'),
			'Model'=>Functions::FormArgs('Model'),
			'RegisterdCapital'=>Functions::FormArgs('RegisterdCapital'),
			'EstablishedTime'=>Functions::FormArgs('EstablishedTime'),
			'Trade'=>Functions::FormArgs('Trade'),
			'Trade_Class'=>Functions::FormArgs('Trade_Class_Value'),
			'Trade_Subclass'=>Functions::FormArgs('Trade_Subclass_Value'),
			'Partner'=>Functions::FormArgs('Partner'),
			'Product'=>Functions::FormArgs('Product'),
			'Province'=>$_POST['Province'],
			'City'=>$_POST['City'],
			'Address'=>Functions::FormArgs('Address'),
			'Intro'=>Functions::FormArgs('Intro',60000,FALSE),
			'Linkman'=>Functions::FormArgs('Linkman'),
			'Sex'=>Functions::FormArgs('Sex'),
			'Department'=>Functions::FormArgs('Department'),
			'Position'=>Functions::FormArgs('Position'),
			'URL'=>Functions::FormArgs('URL'),
			'Phone'=>Functions::FormArgs('Phone'),
			'Fax'=>Functions::FormArgs('Fax'),
			'MSISDN'=>Functions::FormArgs('MSISDN'),
			'QQ'=>Functions::FormArgs('QQ'),
			'MSN'=>Functions::FormArgs('MSN'),

			'M_IsTop'=>Functions::FormArgs('M_IsTop')
			
		);

		if($PassWord) 
		{
			$PassWord=Account::EncryptPassword($PassWord,$Username);
			$Data['PassWord']=$PassWord;
		}
		if(Functions::FormArgs('M_IsTop')>0) 
		{
			$Data['M_IsTop_Datetime']=date('Y-m-d G:i:s');
		}
		if($FileName)
		{
			$Data['Logo']=$FileName;
		}
		//Functions::Print_r($Data);
		// 判断 该会员是否为诚信供应商、vip、email验证会员、锁定 开始
		//取回状态值
		DB::UpdateRowByID('account',Functions::FormArgs('ai'),$Data);
		$data_email=DB::GetRows('select Account from `account_email_verification` where Account=\''.$Username.'\'');
		if($data_email)
		{
			$email_num=1;
		}
		else
		{
			$email_num=0;
		}
		$data_locked=DB::GetRows('select Account from `account_locked` where Account=\''.$Username.'\'');
		if($data_locked)
		{
			$locked_num=1;
		}
		else
		{
			$locked_num=0;
		}
		$data_vip=DB::GetRows('select Account from `account_vip` where Account=\''.$Username.'\'');
		if($data_vip)
		{
			$vip_num=1;
		}
		else
		{
			$vip_num=0;
		}
		$data_integrity=DB::GetRows('select Account from `account_integrity` where Account=\''.$Username.'\'');
		if($data_integrity)
		{
			$integrity_num=1;
		}
		else
		{
			$integrity_num=0;
		}
		//比较状态值 如果值相同则表示该参数未曾修改，将不予改动
		if($email_num!=Functions::FormArgs('M_Email'))
		{
			if(Functions::FormArgs('M_Email')>0) 
			{
				DB::Insert('account_email_verification',array
				(
					'Account'=>$Username,
					'Datetime'=>date('Y-m-d G:i:s')
				));
			}
			else
			{
				DB::CExec('delete from account_email_verification where Account=\''.$Username.'\'');	
			}
		}
		if($locked_num!=Functions::FormArgs('M_locked'))
		{
			if(Functions::FormArgs('M_locked')>0) 
			{
				DB::Insert('account_locked',array
				(
					'Account'=>$Username,
					'Datetime'=>date('Y-m-d G:i:s')
				));
			}
			else
			{
				DB::CExec('delete from account_locked where Account=\''.$Username.'\'');	
			}
		}
		if($vip_num!=Functions::FormArgs('M_Vip'))
		{
			if(Functions::FormArgs('M_Vip')>0) 
			{
				DB::Insert('account_vip',array
				(
					'Account'=>$Username,
					'Datetime'=>date('Y-m-d G:i:s')
				));
			}
			else
			{
				DB::CExec('delete from account_vip where Account=\''.$Username.'\'');	
			}
		}
		
		if($integrity_num!=Functions::FormArgs('M_Integrity'))
		{
			if(Functions::FormArgs('M_Integrity')>0) 
			{
				DB::Insert('account_integrity',array
				(
					'Account'=>$Username,
					'Datetime'=>date('Y-m-d G:i:s')
				));
			}
			else
			{
				DB::CExec('delete from account_integrity where Account=\''.$Username.'\'');	
			}
		}
		
		if($integrity_num!=Functions::FormArgs('M_IsPowerful'))
		{						
			if(Functions::FormArgs('M_IsPowerful')>0) 
			{
				DB::Insert('account_powerful',array
				(
					'Account'=>$Username,
					'Datetime'=>date('Y-m-d G:i:s')
				));
			}
			else
			{
				DB::CExec('delete from account_powerful where Account=\''.$Username.'\'');	
			}
		}
		else
		{
			DB::CExec('delete from account_powerful where Account=\''.$Username.'\'');	
		}
		
		echo '{"Number":"0","Description":"修改成功"}';
    }
?>